package com.wannengbang.cloudleader.mine.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.bean.AddressListBean;
import com.wannengbang.cloudleader.bean.ItemListDTO;
import com.wannengbang.cloudleader.utils.DateTimeUtil;
import com.wannengbang.cloudleader.utils.NumberFormatUtils;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 消息列表
 */
public class RedEnvelopeLatestAdapter extends RecyclerView.Adapter<RedEnvelopeLatestAdapter.ViewHolder> {

    private List<ItemListDTO.DataBean.itemList> listsBeans;
    private Context context;
    private onCallBackListener onCallBackListener;

    public void setOnCallBackListener(RedEnvelopeLatestAdapter.onCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }

    public RedEnvelopeLatestAdapter(List<ItemListDTO.DataBean.itemList> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_red_envelope_latest_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ItemListDTO.DataBean.itemList dataBean = listsBeans.get(position);
        String create_time = DateTimeUtil.format8_brief(new Date(Long.parseLong(dataBean.getCreate_time() + "") * 1000));
        String money = NumberFormatUtils.formatTwoDecimal(Double.parseDouble(dataBean.getMoney() + "") / 100);
        holder.tvName.setText(dataBean.getAgent_name()+create_time+"获取红包"+money+"元");

    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_name)
        TextView tvName;


        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface onCallBackListener {
        void onCallBack(int type, int position);
    }
}
